home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1 / Ian and Stuart's One (Australia).iso / Australasian Legends / Commercial / Rainbow Hill / MacDOS™ 2.0.0 / batches / addPath.bat < prev    next >
DOS Batch File  |  1994-08-26  |  2KB  |  71 lines

  1. @echo off
  2. !  addPath.bat    Batch file to insert a folder in the PATH
  3. !
  4. !  addPath fold skip
  5. !
  6. !  'fold' is the folder to be inserted
  7. !  'skip' is how many existing folders have to be skipped before inserting
  8. !         the new folder. If it is missing, the new folder is appended to
  9. !         the end of the path.
  10. !
  11. !  Example:
  12. !    addPath applied to the initial PATH "first;second;third" will have the
  13. !    following results:
  14. !        addPath xxx                    first;second;third;xxx
  15. !        addPath xxx 0                xxx;first;second;third
  16. !        addPath xxx 1                first;xxx;second;third
  17. !        addPath xxx 2                first;second;xxx;third
  18. !        addPath xxx 3                first;second;third;xxx
  19. !        ...
  20. !        addPath xxx 57                first;second;third;xxx
  21. !
  22. !  Copyright © 1994 by Rainbow Hill Pty Ltd. All rights reserved.
  23. !
  24.  
  25.     set addPath_saved_path=%PATH%
  26.  
  27.     ! ensure that the first parameter is there
  28.     set doserr=13
  29.     if "%1 " == " " goto ERR_LBL
  30.  
  31.     ! determine the position
  32.     if "%2 " == " " goto AT_END_LBL
  33.     set addPath_skip=%2
  34.  
  35.     !
  36.     ! scan the existing PATH and skip one folder at a time until you reach
  37.     ! the requested position or until you run out of folders
  38.     !
  39.     set addPath_tail=%PATH%
  40.     set doserr=0
  41. :SKIP_ONE_LBL
  42.     if %addPath_skip% == 0 goto POS_FOUND_LBL
  43.     if "%addPath_tail%" == %%ADDPATH_TAIL%% goto AT_END_LBL
  44.     sstr addPath_tail ; /R
  45.     if %doserr% == 72 goto AT_END_LBL
  46.     decr addPath_skip
  47.     goto SKIP_ONE_LBL
  48.  
  49. :AT_END_LBL
  50.     !
  51.     ! append the new folder to the end
  52.     incr path by ";%1"
  53.     goto DONE_LBL
  54.  
  55. :POS_FOUND_LBL
  56.     !
  57.     ! insert the new folder in the appropriate position
  58.     decr path by "%addPath_tail%"
  59.     incr path by "%1;%addPath_tail%"
  60.     goto DONE_LBL
  61.  
  62. :ERR_LBL
  63.     show %doserr%
  64.     set path=%addPath_saved_path%
  65.  
  66. :DONE_LBL
  67.     ! remove the global variables
  68.     set addPath_skip=
  69.     set addPath_tail=
  70.     set addPath_saved_path=
  71.